
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
  <title>CheckPIESupported &mdash; CMake 3.16.5 Documentation</title>

    <link rel="stylesheet" href="../_static/cmake.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    
    <link rel="shortcut icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="CheckPrototypeDefinition" href="CheckPrototypeDefinition.html" />
    <link rel="prev" title="CheckOBJCXXSourceRuns" href="CheckOBJCXXSourceRuns.html" />
  
 

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="CheckPrototypeDefinition.html" title="CheckPrototypeDefinition"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="CheckOBJCXXSourceRuns.html" title="CheckOBJCXXSourceRuns"
             accesskey="P">previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.16.5 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" accesskey="U">cmake-modules(7)</a> &#187;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="checkpiesupported">
<span id="module:CheckPIESupported"></span><h1>CheckPIESupported<a class="headerlink" href="#checkpiesupported" title="Permalink to this headline">¶</a></h1>
<p>Check whether the linker supports Position Independent Code (PIE) or No
Position Independent Code (NO_PIE) for executables.
Use this to ensure that the <span class="target" id="index-0-prop_tgt:POSITION_INDEPENDENT_CODE"></span><a class="reference internal" href="../prop_tgt/POSITION_INDEPENDENT_CODE.html#prop_tgt:POSITION_INDEPENDENT_CODE" title="POSITION_INDEPENDENT_CODE"><code class="xref cmake cmake-prop_tgt docutils literal notranslate"><span class="pre">POSITION_INDEPENDENT_CODE</span></code></a> target
property for executables will be honored at link time.</p>
<dl class="command">
<dt id="command:check_pie_supported">
<code class="sig-name descname">check_pie_supported</code><a class="headerlink" href="#command:check_pie_supported" title="Permalink to this definition">¶</a></dt>
<dd><div class="highlight-none notranslate"><div class="highlight"><pre><span></span>check_pie_supported([OUTPUT_VARIABLE &lt;output&gt;]
                    [LANGUAGES &lt;lang&gt;...])
</pre></div>
</div>
<p>Options are:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">OUTPUT_VARIABLE</span> <span class="pre">&lt;output&gt;</span></code></dt><dd><p>Set <code class="docutils literal notranslate"><span class="pre">&lt;output&gt;</span></code> variable with details about any error.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">LANGUAGES</span> <span class="pre">&lt;lang&gt;...</span></code></dt><dd><p>Check the linkers used for each of the specified languages.
Supported languages are <code class="docutils literal notranslate"><span class="pre">C</span></code>, <code class="docutils literal notranslate"><span class="pre">CXX</span></code>, and <code class="docutils literal notranslate"><span class="pre">Fortran</span></code>.</p>
</dd>
</dl>
</dd></dl>

<p>It makes no sense to use this module when <span class="target" id="index-0-policy:CMP0083"></span><a class="reference internal" href="../policy/CMP0083.html#policy:CMP0083" title="CMP0083"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0083</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">OLD</span></code>,
so the command will return an error in this case.  See policy <span class="target" id="index-1-policy:CMP0083"></span><a class="reference internal" href="../policy/CMP0083.html#policy:CMP0083" title="CMP0083"><code class="xref cmake cmake-policy docutils literal notranslate"><span class="pre">CMP0083</span></code></a>
for details.</p>
<div class="section" id="variables">
<h2>Variables<a class="headerlink" href="#variables" title="Permalink to this headline">¶</a></h2>
<p>For each language checked, two boolean cache variables are defined.</p>
<blockquote>
<div><dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_&lt;lang&gt;_LINK_PIE_SUPPORTED</span></code></dt><dd><p>Set to <code class="docutils literal notranslate"><span class="pre">YES</span></code> if <code class="docutils literal notranslate"><span class="pre">PIE</span></code> is supported by the linker and <code class="docutils literal notranslate"><span class="pre">NO</span></code> otherwise.</p>
</dd>
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_&lt;lang&gt;_LINK_NO_PIE_SUPPORTED</span></code></dt><dd><p>Set to <code class="docutils literal notranslate"><span class="pre">YES</span></code> if <code class="docutils literal notranslate"><span class="pre">NO_PIE</span></code> is supported by the linker and <code class="docutils literal notranslate"><span class="pre">NO</span></code> otherwise.</p>
</dd>
</dl>
</div></blockquote>
</div>
<div class="section" id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h2>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">check_pie_supported()</span><span class="w"></span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">foo</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">POSITION_INDEPENDENT_CODE</span><span class="w"> </span><span class="no">TRUE</span><span class="nf">)</span><span class="w"></span>
</pre></div>
</div>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="c"># Retrieve any error message.</span>
<span class="nf">check_pie_supported(</span><span class="no">OUTPUT_VARIABLE</span><span class="w"> </span><span class="nb">output</span><span class="w"> </span><span class="no">LANGUAGES</span><span class="w"> </span><span class="no">C</span><span class="nf">)</span><span class="w"></span>
<span class="nf">set_property(</span><span class="no">TARGET</span><span class="w"> </span><span class="nb">foo</span><span class="w"> </span><span class="no">PROPERTY</span><span class="w"> </span><span class="no">POSITION_INDEPENDENT_CODE</span><span class="w"> </span><span class="no">TRUE</span><span class="nf">)</span><span class="w"></span>
<span class="nf">if(</span><span class="no">NOT</span><span class="w"> </span><span class="no">CMAKE_C_LINK_PIE_SUPPORTED</span><span class="nf">)</span><span class="w"></span>
<span class="w">  </span><span class="nf">message(</span><span class="no">WARNING</span><span class="w"> </span><span class="s">&quot;PIE is not supported at link time: ${output}.\n&quot;</span><span class="w"></span>
<span class="w">                  </span><span class="s">&quot;PIE link options will not be passed to linker.&quot;</span><span class="nf">)</span><span class="w"></span>
<span class="nf">endif()</span><span class="w"></span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">CheckPIESupported</a><ul>
<li><a class="reference internal" href="#variables">Variables</a></li>
<li><a class="reference internal" href="#examples">Examples</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="CheckOBJCXXSourceRuns.html"
                        title="previous chapter">CheckOBJCXXSourceRuns</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="CheckPrototypeDefinition.html"
                        title="next chapter">CheckPrototypeDefinition</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/module/CheckPIESupported.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="CheckPrototypeDefinition.html" title="CheckPrototypeDefinition"
             >next</a> |</li>
        <li class="right" >
          <a href="CheckOBJCXXSourceRuns.html" title="CheckOBJCXXSourceRuns"
             >previous</a> |</li>
  <li>
    <img src="../_static/cmake-logo-16.png" alt=""
         style="vertical-align: middle; margin-top: -2px" />
  </li>
  <li>
    <a href="https://cmake.org/">CMake</a> &#187;
  </li>
  <li>
    <a href="../index.html">3.16.5 Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" >cmake-modules(7)</a> &#187;</li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2000-2019 Kitware, Inc. and Contributors.
      Created using <a href="http://sphinx-doc.org/">Sphinx</a> 2.3.1.
    </div>
  </body>
</html>